#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int pan(char *str) {
	int len = strlen(str);
	if (len == 3) {
		if (str[0] == str[1] && str[1] == str[2]) {
			return 1;
		} else {
			return 0;
		}
	} else {
		return 0;
	}
}

void del2(char *str, int pos) {
	pos = pos - 1;
	char str1[21];
	strcpy(str1, str);
	int count = 0;
	int index = 0;
	str1[pos] = str1[pos - 1];
	int i = pos;
	while (str1[i] == str1[pos] && i < strlen(str1)) {
		i++;
		count++;
	}
	i = pos;
	count--;
	while (str1[i] == str1[pos] && i >= 0) {
		i--;
		count++;
	}

	if (count < 3) {
		str[pos] = str[pos - 1];
	} else {
		for (int j = 0; j <= i; j++) {
			str[index++] = str[j];
		}
		for (int j = i + count + 1 ; j < strlen(str1); j++) {
			str[index++] = str[j];
		}
	}
	str[index] = 0;
	if (index == 0) {
		printf("You win!");
		exit(1);
	}
}

void del1(char *str) {
	char str1[21];
	strcpy(str1, str);
	int count = 1;
	int index = 0;
	for (int i = 1; i < strlen(str1); i++) {
		if (i == strlen(str1) - 1) {
			if (str1[i] == str[i - 1] && count == 1) {
				for (int j = 0; j < count + 1; j++) {
					str[index++] = str1[i];

				}
			} else if (str1[i] != str[i - 1]) {
				for (int j = 0; j < count ; j++) {
					str[index++] = str1[i - 1];

				}
				str[index++] = str1[i];

			}
			break;
		}
		if (str1[i] == str[i - 1]) {
			count++;
		} else {
			if (count >= 3) {
				;
			} else {
				for (int j = 0; j < count; j++) {
					str[index++] = str[i - 1];
				}
			}
			count = 1;
		}

	}
	str[index] = 0;
	if (index == 0) {
		printf("You win!");
		exit(1);
	}
}


void del(char *str, int len, char jian, int pos) {
	int i, sum = -1, j = 0, loc = pos, tag = 0, sign = 0;
	char temp[len], di = str[0];

	for (i = pos - 1; i >= 0; i--) {
		if (str[i] == jian) {
			loc = i;
			sum++;
		} else {
			break;
		}
	}
	for (i = pos - 1; i < len; i++) {
		if (str[i] == jian) {
			sum++;
		} else {
			break;
		}
	}
	if (sum >= 3) {
		sign = 1;
	}
	if (sign == 1) {
		if (loc == 0) {
			for (i = loc + sum; i < len; i++) {
				temp[j] = str[i];
				j++;
			}
		} else if (loc + sum == len) {
			for (i = 0; i < loc; i++) {
				temp[j] = str[i];
				j++;
			}
		} else {
			for (i = 0; i < loc; i++) {
				temp[j] = str[i];
				j++;
			}
			for (i = loc + sum; i < len; i++) {
				temp[j] = str[i];
				j++;
			}
		}

		temp[j] = '\0';
//	printf("%s,%d,%d\n",temp,loc,sum);
		strcpy(str, temp);
	}
}

int main() {
	char str[20];
	scanf("%s", str);
	int len = strlen(str);

	while (1) {
		char ch;
		int pos;
		if (scanf(" %c%d", &ch, &pos) != 2) {
			break;
		}
		if (ch == '@') {
			del1(str);
			printf("%s\n\n", str);
			continue;
		}
		if (ch == '#') {
			del2(str, pos);
			printf("%s\n\n", str);
			continue;
		}
		if (pos < 0 || pos > len) {
			printf("Invalid position. Please try again.\n");
			continue;
		}
		if (pos == 1) {
			for (int i = len; i >= pos; i--) {
				str[i] = str[i - 1]; // Shift elements to the right
			}
			str[pos - 1] = ch;
			len++;
			str[len] = '\0';
		} else {
			for (int i = len; i >= pos; i--) {
				str[i] = str[i - 1]; // Shift elements to the right
			}
			str[pos] = ch;
			len++;
			str[len] = '\0';
		}
		if (pan(str) == 1) {
			printf("You win!");
			break;
		}
		del(str, len, ch, pos);
		if (strlen(str) == 0) {
			printf("You win!");
			break;
		}
		printf("%s\n\n", str);


	}

	return 0;
}
